package com.lovo.cloud.service.impl;

import com.lovo.cloud.service.PermissionService;
import com.lovo.model.dos.UserDO;
import com.lovo.model.dto.UserDTO;
import com.lovo.util.TokenUtil;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author luo
 * @description
 * @date 2020/12/1 17:17
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    private static List<UserDO> list = new ArrayList<>();

    static {
        List<String> zy = new ArrayList<>();
        zy.add("login1");
        zy.add("login2");
        List<String> mc = new ArrayList<>();
        mc.add("login1");
        mc.add("login3");
        UserDO zhaoyun = new UserDO(1,"zy","12345",zy);
        UserDO machao = new UserDO(2,"mc","123456",mc);
        list.add(zhaoyun);
        list.add(machao);
    }

    @Override
    public List<String> getPermissions(String username) {

        return list.get(list.indexOf(username)).getPermissions();
    }

    @Override
    public Boolean isLogin(UserDTO userDTO) {
        boolean bl = false;
        if (userDTO == null || userDTO.getUserName() == null || userDTO.getUserPwd() ==null) {
            return bl;
        }
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getUserName().equals(userDTO.getUserName()) &&
                    list.get(i).getUserPwd().equals(userDTO.getUserPwd())) {
                bl = true;
            }
        }
        return bl;
    }
}
